import { createRouter, createWebHistory } from "vue-router";
import HomeView from "@/views/HomeView.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_L),
  routes: [
    {
      path: "/",
      name: "root",
      component: HomeView,
      redirect: "/home",
      children: [
        {
          path: "home",
          name: "Home",
          component: () => import("@/views/home/index.vue"),
        },
        {
          path: "/learning",
          name: "Learning",
          component: () => import("@/views/learning/home.vue"),
          redirect: "/learning/index",
          meta: {
            roles: ["TA", "PA", "补差", "admin"],
          },
          children: [
            {
              path: "index",
              name: "LearningIndex",
              component: () => import("@/views/learning/index.vue"),
            },
            {
              path: "statistics",
              name: "LearningStatistics",
              component: () => import("@/views/learning/statistics/home.vue"),
            },
            {
              path: "learn",
              name: "LearningLearn",
              component: () => import("@/views/learning/learn.vue"),
            },
            {
              path: "selfTest",
              name: "SelfTest",
              component: () => import("@/views/learning/selfTest.vue"),
            },
            {
              path: "review",
              name: "Review",
              component: () => import("@/views/learning/review.vue"),
            },

            {
              path: "listening",
              name: "Listening",
              component: () => import("@/views/learning/listening.vue"),
            },
            {
              path: "listening/practice",
              name: "Practice",
              component: () => import("@/views/learning/practice.vue"),
            },
          ],
        },
        {
          path: "/simulator",
          name: "Simulator",
          component: () => import("@/views/learning/simulator/home.vue"),
          redirect: "/simulator/UpperDu",
          children: [
            {
              path: "UpperDu",
              name: "SimulatorHome",
              component: () =>
                import(
                  "@/views/learning/simulator/components/upper/UpperDu.vue"
                ),
            },
            {
              path: "fltctl",
              name: "fltctl",
              component: () =>
                import(
                  "@/views/learning/simulator/components/lower/Flt/FltCtl.vue"
                ),
            },
            {
              path: "fuel",
              name: "fuel",
              component: () =>
                import(
                  "@/views/learning/simulator/components/lower/Fuel/index.vue"
                ),
            },
            {
              path: "elec",
              name: "elec",
              component: () =>
                import(
                  "@/views/learning/simulator/components/lower/Elec/index.vue"
                ),
            },
            {
              path: "hyd",
              name: "hyd",
              component: () =>
                import(
                  "@/views/learning/simulator/components/lower/Hyd/index.vue"
                ),
            },
          ],
        },
        {
          path: "/test",
          name: "Test",
          component: () => import("@/views/test/home.vue"),
          redirect: "/test/index",
          meta: {
            roles: ["TA", "PA", "补差", "admin"],
          },
          children: [
            {
              path: "index",
              name: "TestIndex",
              component: () => import("@/views/test/index.vue"),
            },
            {
              path: "startTest",
              name: "StartTest",
              component: () => import("@/views/learning/selfTest.vue"),
            },
            {
              path: "result",
              name: "Result",
              component: () => import("@/views/test/result.vue"),
            },
            {
              path: "answer",
              name: "Answer",
              component: () => import("@/views/test/answer.vue"),
            },
            {
              path: "echarts",
              name: "Echarts",
              component: () => import("@/views/test/analysis/index.vue"),
              redirect: "/test/echarts/analysis",
              children: [
                {
                  path: "analysis",
                  name: "Analysis",
                  component: () => import("@/views/test/analysis/analysis.vue"),
                },
                {
                  path: "statistics",
                  name: "Statistics",
                  component: () =>
                    import("@/views/test/analysis/statistics.vue"),
                },
                {
                  path: "subject",
                  name: "Subject",
                  component: () => import("@/views/test/analysis/subject.vue"),
                },
              ],
            },
          ],
        },
        {
          path: "/training",
          name: "Training",
          component: () => import("@/views/training/home.vue"),
          redirect: "/training/index",
          children: [
            {
              path: "index",
              name: "TrainingIndex",
              component: () => import("@/views/training/index.vue"),
            },
            {
              path: "video",
              name: "Video",
              component: () => import("@/views/training/video.vue"),
            },
            {
              path: "exam",
              name: "Exam",
              component: () => import("@/views/learning/selfTest.vue"),
            },
            {
              path: "pdf-viewer",
              name: "PdfViewer",
              component: () => import("@/components/PdfViewer.vue"),
            },
            {
              path: "certificate",
              name: "Certificate",
              component: () => import("@/views/training/certificate.vue"),
            },
          ],
        },
      ],
    },
    {
      path: "/login",
      component: () => import("@/views/login/index.vue"),
      hidden: true,
    },
    {
      path: "/404",
      name: "404",
      component: () => import("@/views/404.vue"),
    },
    // 这个必须放在最后！
    {
      path: "/:pathMatch(.*)*",
      redirect: "/404",
    },
  ],
});

export default router;
